using HardMock.Domain;

namespace HardMock.Recording
{
    internal class PropertyCallIdentifierFactory : IIdentifierFactory
    {
        private readonly IIdentifierFactory identifierFactory;
        private readonly IIdentifierFactory propertyCallIdentifierFactory;

        public PropertyCallIdentifierFactory(IIdentifierFactory identifierFactory)
        {
            this.identifierFactory = identifierFactory;
            propertyCallIdentifierFactory = new StateFullIdentifierFactory(identifierFactory);
        }

        public string Create(MethodCall methodCall)
        {
            return IsProperty(methodCall) ? propertyCallIdentifierFactory.Create(methodCall) : identifierFactory.Create(methodCall);
        }

        private static bool IsProperty(MethodCall methodCall)
        {
            var methodName = methodCall.Name;
            return methodName.Contains("get_") || methodName.Contains("set_");
        }
    }
}